//
//  XYBusinessDetailCell1.m
//  Zhihuijinfu
//
//  Created by XY Lv on 17/3/21.
//  Copyright © 2017年 王笛. All rights reserved.
//

#import "XYBusinessDetailCell1.h"

@implementation XYBusinessDetailCell1

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self  = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        [self xyInitSubviews];
        //[self xySetSubviewsColor];

        [self xyInitCellStyle];
        [self xySetSubviewsStyle];
    }
    return self;
}

- (void)xyInitCellStyle{
    self.selectionStyle = UITableViewCellSelectionStyleNone;
}

- (void)xyInitSubviews{
    self.xyIconImgView = [[UIImageView alloc]init];
    [self addSubview:self.xyIconImgView];
    
    self.xyIconImgViewLine = [[UIImageView alloc]init];
    [self addSubview:self.xyIconImgViewLine];
    
    self.xyTitleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:self.xyTitleBtn];
    
    self.xyTimeLable = [[UILabel alloc]init];
    [self addSubview:self.xyTimeLable];
    
//    self.xyLocalImgView = [[UIImageView alloc]init];
//    [self addSubview:self.xyLocalImgView];
    
//    self.xyLocalLabel = [UIButton buttonWithType:UIButtonTypeCustom];
//    [self addSubview:self.xyLocalBtn];
    self.xyLocalAlertView = [[XYLocalAlertView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    self.xyLocalAlertView.xyAligment = XYLayoutLeft;
    [self addSubview:self.xyLocalAlertView];
    
    self.xyContentLabel = [[UILabel alloc]init];
    [self addSubview:self.xyContentLabel];
    
    self.xyPhotoPlaceholderImgView = [[UIImageView alloc]init];
    [self addSubview:self.xyPhotoPlaceholderImgView];
    
    self.xyPhotoImgView = [[UIImageView alloc]init];
    [self addSubview:self.xyPhotoImgView];
    
    self.xyMessageBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:self.xyMessageBtn];
}

- (void)xySetSubviewsStyle{
    self.xyTitleBtn.layer.masksToBounds = YES;
    
    [self.xyTitleBtn setTitleColor:ColorForRGB(0xFFFFFF) forState:UIControlStateNormal];
    self.xyTitleBtn.titleLabel.font = [UIFont systemFontOfSize:10];
    
    self.xyTimeLable.text = @"2017-03-21 11:47";
    self.xyTimeLable.textAlignment = NSTextAlignmentRight;
    self.xyTimeLable.font = [UIFont systemFontOfSize:11];
    self.xyTimeLable.textColor = ColorForRGB(0xA0A0A0);
    
    [self.xyLocalImgView setImage:[UIImage imageNamed:@"xy_icon-location"]];
    
//    self.xyLocalLabel.titleLabel.font = [UIFont systemFontOfSize:xy(11)];
//    self.xyLocalLabel.titleLabel.textAlignment = NSTextAlignmentLeft;
//    [self.xyLocalLabel setTitleColor:ColorForRGB(0xA0A0A0) forState:UIControlStateNormal];
    self.xyLocalAlertView.backgroundColor = nil;
    self.xyLocalAlertView.xyLocalTextLabel.textColor = ColorForRGB(0xA0A0A0);
    self.xyContentLabel.font = [UIFont systemFontOfSize:xy(12)];
    self.xyContentLabel.numberOfLines = 0;
    self.xyContentLabel.lineBreakMode = NSLineBreakByTruncatingTail;
    
    self.xyPhotoImgView.contentMode = UIViewContentModeScaleToFill;
    
    [self.xyMessageBtn setImage:[UIImage imageNamed:@"xy_icon_comment"] forState:UIControlStateNormal];
    self.xyMessageBtn.titleLabel.font = [UIFont systemFontOfSize:xy(11)];
    self.xyMessageBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -xyPadding/2, 0, 0);
    self.xyMessageBtn.titleEdgeInsets = UIEdgeInsetsMake(0, xyPadding/2, 0, 0);
    [self.xyMessageBtn setTitleColor:WDNavSeleColor forState:UIControlStateNormal];

}

- (void)xySetSubviewsColor{
    self.xyIconImgView.backgroundColor = [UIColor yellowColor];
    self.xyTimeLable.backgroundColor = [UIColor yellowColor];
    self.xyContentLabel.backgroundColor = [UIColor greenColor];
    self.xyMessageBtn.backgroundColor = [UIColor orangeColor];
//    self.xyLocalBtn.backgroundColor = [UIColor brownColor];
    self.xyPhotoImgView.backgroundColor= [UIColor yellowColor];
}

- (void)setXyDetailFrame:(XYBusinessDetailFrame *)xyDetailFrame{
    _xyDetailFrame = xyDetailFrame;
    [self xySetSubviewsFrameWithFrame:xyDetailFrame];
    [self xySetSubviewsDataWithFrame:xyDetailFrame];
}

- (void)xySetSubviewsFrameWithFrame:(XYBusinessDetailFrame *)frame{
    self.xyIconImgView.frame = frame.xyIconImgViewF;
    self.xyIconImgViewLine.frame = frame.xyIconImgViewLineF;
    self.xyTitleBtn.frame= frame.xyTitleBtnF;
    self.xyTimeLable.frame = frame.xyTimeLableF;

    self.xyLocalAlertView.frame = frame.xyLocalAlertViewF;
    self.xyContentLabel.frame = frame.xyContentLabelF;
    self.xyPhotoPlaceholderImgView.frame = frame.xyPhotoPlaceholderF;

    self.xyPhotoImgView.frame = frame.xyPhotoImgViewF;
    self.xyMessageBtn.frame = frame.xyMessageBtnF;
    self.xyTitleBtn.layer.cornerRadius = self.xyDetailFrame.xyTitleBtnF.size.height/2;

}

- (void)xySetSubviewsDataWithFrame:(XYBusinessDetailFrame *)frame{
    
    [self.xyIconImgView setImage:[UIImage imageNamed:@"xy_icon-ball"]];
    
    [self.xyIconImgViewLine setImage:[UIImage imageNamed:@"xy_icon-line"]];
    self.xyLocalAlertView.hidden = YES;
    if([frame.xyDetailItem.type isEqualToString:@"2"]){
        self.xyTitleBtn.backgroundColor = [UIColor colorWithRed:0.30 green:0.57 blue:0.87 alpha:1.00];
        [self.xyTitleBtn setTitle:@"面访签到" forState:UIControlStateNormal];
        self.xyLocalAlertView.hidden = NO;

    }else if([frame.xyDetailItem.type isEqualToString:@"1"]){
        self.xyTitleBtn.backgroundColor = [UIColor colorWithRed:0.95 green:0.65 blue:0.22 alpha:1.00];
        [self.xyTitleBtn setTitle:@"电话回访" forState:UIControlStateNormal];
    }else if([frame.xyDetailItem.type isEqualToString:@"0"]){
        self.xyTitleBtn.backgroundColor = [UIColor grayColor];
        [self.xyTitleBtn setTitle:@"创建商户" forState:UIControlStateNormal];
        self.xyMessageBtn.hidden = YES;
        self.xyIconImgViewLine.hidden = YES;
    }
    
    self.xyTimeLable.text = frame.xyDetailItem.create_time;
//    [self.xyLocalLabel setTitle:frame.xyDetailItem.address forState:UIControlStateNormal];
    self.xyLocalAlertView.xyLocalStr = frame.xyDetailItem.address;

    
    self.xyContentLabel.text = frame.xyDetailItem.content;
    if(frame.xyDetailItem.file_data.count >0&&[frame.xyDetailItem.type isEqualToString:@"2"]){
        
        [self.xyPhotoPlaceholderImgView setImage:[UIImage imageNamed:@"xy_icon_photoPlaceholder"]];
        NSString * thumbnail;
        if(frame.xyDetailItem.file_data.count >0){
            thumbnail = [frame.xyDetailItem.file_data[0] objectForKey:@"thumbnail"];
        }
    
        [self.xyPhotoImgView sd_setImageWithURL:[NSURL URLWithString:thumbnail] placeholderImage:[UIImage imageNamed:@""]];
    }else{
//        self.xyPhotoPlaceholderImgView.hidden = YES;

    }
    
    
    [self.xyMessageBtn setTitle:frame.xyDetailItem.chat_count forState:UIControlStateNormal];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end













